<!doctype html>
<html>
<head>
<meta charset="">
<link type="text/css" rel="stylesheet" href="css/base.css" />
<link type="text/css" rel="stylesheet" href="css/tipsy.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.tipsy.js"></script>
<script type="text/javascript">
var gid = function(i){return document.getElementById(i);}
var Controller = function(){return chrome.extension.getBackgroundPage()};
var total = 0,aid,last_id,Interval,isUp = false,LoginUp,Iniciado;
var db = Controller().db;
var Slogan = Traduz('slogan');
var EspecialChars = ["\u263A","\u263B","\u2605","\u2606","\u2217","\u2731","\u263C","\u2640","\u2642","\u266A","\u266B","\u2022","\u2660","\u2663","\u2665","\u2666","\u2020","\u2021","\u2105","\u25B2","\u25BA","\u25BC","\u25C4","\u2122"];

var AtivaLog = true;
var Trava = false;

function log(a){
  if(AtivaLog) console.log(a);
}
var bActive = false;
function Active(e){
    if(bActive[0]){
        if(bActive[0].id == 'blists'){
            SelList(bActive, true);
        }
        bActive.attr('active', 'false');
    }
    e.attr('active', 'true');
    bActive = e;
}

function SwichPainel(){
  if(Controller().config.ShowPainel){
      Controller().config.ShowPainel = false;
      $('.info').slideUp();
      $('#PainelSeta').attr('src', 'img/seta_down.png');
  }else{
      Controller().config.ShowPainel = true;
      $('.info').slideDown();
      $('#PainelSeta').attr('src', 'img/seta_up.png');
  }
  $('#PainelSeta').show();
}

function Scroll(event){
    if(db.pega('AbaAtiva') == 'list'){
        Controller().tws.list[event.data.lista].scroll = $('#twets_list')[0].scrollTop;
    }else{
        Controller().Chrowety[event.data.lista].scroll = $('#twets_'+event.data.lista)[0].scrollTop;
    }
}

var LT = {
    Auto:function(){	
        if(db.pega('AbaAtiva')){
		  LT.Unreads();
          if(db.pega('AbaAtiva') == 'list' && Controller().tws.list[db.pega('ListAtiva')]){
			if(!Controller().tws.list[db.pega('ListAtiva')].ativo){
				LT.home();	
			}else{
				LT.list(db.pega('ListAtiva'));	
			}
          }else{
            LT[db.pega('AbaAtiva')]();
          }
        }else{
          LT.home();
        }
    },

	ClearUnreads:function(name){
		$('#b'+name).attr('count', Controller().tws.mentions.new_count);
		$('#b'+name).blur();
	},
	
	Unreads:function(){
		 var tws = Controller().tws;
		 //$('#bhome').blur();
		 //$('#bmetions').blur();
		 //$('#bmessages').blur(); 		 
		 $('#bhome').attr('count', tws.home.new_count).tipsy();
		 $('#bmentions').attr('count', tws.mentions.new_count).tipsy();
		 $('#bmessages').attr('count', tws.messages.new_count).tipsy();
		 $('#bhome').hover();
		 $('#bmentions').hover();
		 $('#bmessages').hover();
	},

    more:function(name, hide, show){
        //var name = 'more';
        var b = $('#b'+name);
        if(b.attr('disabled')) return false;
        //Button.ativa(b);
        if(b.attr('ativo') && !show || hide && !show){
            //$('.twets').css('height', $('.twets').css('height')+10);
            $('#submenu_'+name).slideUp('fast');
            b.removeAttr('ativo');
        }else{
            //$('.twets').css('height', $('.twets').css('height')-10);
            $('#submenu_'+name).slideDown('fast');
            b.attr('ativo', 'true');
        }
    },
    initLists:function(){
        if(Controller().tws.lists && Controller().tws.lists.names){
            $('#submenu_lists').empty();
            nomes = Controller().tws.lists.names;
			var button = null, new_count=0;
            for(i=nomes.length-1; i >= 0; i--){
                if(!Controller().tws.list[nomes[i]].ativo){
                    continue;
                }
                	button = document.createElement('button');
                    button.id = 'b'+nomes[i];
                    button.innerText = nomes[i];
                    button.setAttribute('list', nomes[i]);
                    button.onclick = function(){
                        LT.list(this.getAttribute('list'));
                    };
					$('#submenu_lists').append(button);
					new_count = Controller().tws.list[nomes[i]].new_count ? Controller().tws.list[nomes[i]].new_count : 0;
					$('#b'+nomes[i]).attr('count', new_count).tipsy();
					$('#b'+nomes[i]).hover();					            
            }
            LT.more('lists', null, true);
            LT.Auto();
        }
    },

    loadList:function(name){
        if(!Controller().tws.list[name].ativo){
            if(!Controller().tws.list[name]._loaded){
                $('#show_lists_load_'+name).show();
                $('#lists_'+name)[0].setAttribute('disabled', 'disabled');
				$('#lists_'+name).attr('title', Traduz('add_list'));
                Controller().Chrowety.List.Run(name, 'LT.addList(\''+name+'\')');
            }else{
				$('#lists_'+name).addClass('ds');
				$('#lists_'+name).attr('title', Traduz('remove_list'));
                Controller().tws.list[name].ativo = true;
            }

        }else{
			$('#lists_'+name).removeClass('ds');
			$('#lists_'+name).attr('title', Traduz('add_list'));
            Controller().tws.list[name].ativo = false;
        }
        LT.initLists();
    },

    addList:function(name){
        $('#show_lists_load_'+name).hide();
        $('#lists_'+name).addClass('ds');
		$('#lists_'+name).attr('title', Traduz('remove_list'));
        $('#lists_'+name)[0].removeAttribute('disabled');		
        LT.initLists();
    },

    Lists:function(force){
        $('#user_info').hide();
        ShowPopup();
        $('#show_lists').show();

        if(force){
            $('#show_lists_lists').empty();
            $('#show_lists_load').show();
            $('#show_lists_lists').hide();
            $('#show_lists').attr('loaded', "false");
            Controller().Chrowety.Lists('LT.Lists()');
            return false;
        }

        if(Controller().tws.lists && !Controller().tws.lists.loaded){
            Controller().Chrowety.Lists('LT.Lists()');
            return false;
        }

        if(Controller().tws.lists && Controller().tws.lists.loaded && $('#show_lists').attr('loaded') != "true"){
            nomes = Controller().tws.lists.names;
            fnomes = Controller().tws.lists.full_names;
            var i = 0;
            for(i; i < nomes.length; i++){
                var dn_ok     = Controller().tws.list[nomes[i]].ativo ? 'ds' : '';
                var dn_title  = Controller().tws.list[nomes[i]].ativo ? Traduz('remove_list') : Traduz('add_list');
                var lay =
                '<div onclick="LT.loadList(this.getAttribute(\'list\'));" title="'+dn_title+'" id="lists_'+nomes[i]+'" list="'+nomes[i]+'" class="list '+dn_ok+'">'+
                    '<span class="fl">'+fnomes[i]+'</span>'+
                    '<span class="fr dn" id="show_lists_load_'+nomes[i]+'"><img src="img/load.gif" /></span>'+
                '</div>';
                $('#show_lists_lists').append(lay);
            }
            if(i == 0){
                $('#show_lists_lists').append(Traduz('no_lists_found'));
            }
            $('#show_lists_load').hide();
            $('#show_lists_lists').show();
            $('#show_lists').attr('loaded', "true");
        }
    },

    list:function(name){
        //Controller().console.log('LT.list('+name+')');
        var loaded = Controller().tws.list[name]._loaded;
        if(!loaded){
          Controller().tws.list[name].scroll = 0;
          return false;
        }
        db.salva('AbaAtiva', 'list');
        db.salva('ListAtiva', name);
        var b = $('#b'+name);
        if(b.attr('disabled')) return false;
        Button.ativa(b);
        if(Controller().fec.html(name, null, null, true) != ""){
            var tws = $(Controller().fec.html(name, null, null, true));
            var tsh = $('<div id="showMore_link_list" class="show_more" onclick="ShowMore(\''+name+'\', true)" title="'+Traduz('show_more')+'">'+Traduz('show_more')+'</div>');
        }else{
            var tws = 'No tweets found';
            var tsh = '';
        }
        $('#load_result').text('Loading '+name+'...');
        $('.twets_con').hide();
        $('#tcon_list').show();
        $('#tcon_list').attr('lista', name);
        $('#twets_list').empty();
        $('#twets_list').html(tws);
        $('#twets_list').append(tsh);
        SearchData();
        $('#twets_list')[0].scrollTop = Controller().tws.list[name].scroll;
        $('#twets_list').bind("scroll", {lista:name}, Scroll);
        $('#load').hide();
        LT.ClearUnreads(name);
        window.setTimeout("Controller().ClearUnreads('"+name+"')", 500);
        LT.UISets();
    },

	UISets:function(){
        $('.texwt').css({
            'font-size': Controller().config.tweet_font_size,
            'text-shadow': Controller().config.tweet_shadow,
        });
		$('.twets').css('height', Controller().config.popup_height);
		if(Controller().config.show_username =='true'){$('.tweets_names').show()}		
	},
	
    home:function(){
        var name = 'home';
        var loaded = Controller().Chrowety[name]._loaded;
        if(!loaded){
          Controller().Chrowety[name].scroll = 0;
          Controller().Chrowety[name].Run('LT.'+name+'()');
          return false;
        }
        db.salva('AbaAtiva', name);
        var b = $('#b'+name);
        if(b.attr('disabled')) return false;
        Button.ativa(b);
        if(Controller().fec.html(name) != ""){
            var tws = $(Controller().fec.html(name));
            var tsh = $('<div id="showMore_link_'+name+'" class="show_more" onclick="ShowMore(\''+name+'\')" title="'+Traduz('show_more')+'">'+Traduz('show_more')+'</div>');
        }else{
            var tws = 'No tweets found';
            var tsh = '';
        }
        $('#load_result').text('Loading '+name+'...');
        $('.twets_con').hide();
        $('#tcon_'+name).show();
        $('#twets_'+name).empty();
        $('#twets_'+name).html(tws);
        $('#twets_'+name).append(tsh);
        SearchData();
        $('#twets_'+name)[0].scrollTop = Controller().Chrowety[name].scroll;
        $('#twets_'+name).bind("scroll", {lista:name}, Scroll);
        $('#load').hide();
        LT.ClearUnreads(name);
		window.setTimeout("Controller().ClearUnreads('"+name+"')", 500);
		LT.UISets();
    },
    mentions:function(){
        var name = 'mentions';
        var loaded = Controller().Chrowety[name]._loaded;
        if(!loaded){
          Controller().Chrowety[name].scroll = 0;
          Controller().Chrowety[name].Run('LT.'+name+'()');
          return false;
        }
        db.salva('AbaAtiva', name);
        var b = $('#b'+name);
        if(b.attr('disabled')) return false;
        Button.ativa(b);
        if(Controller().fec.html(name) != ""){
            var tws = $(Controller().fec.html(name));
            var tsh = $('<div id="showMore_link_'+name+'" class="show_more" onclick="ShowMore(\''+name+'\')" title="'+Traduz('show_more')+'">'+Traduz('show_more')+'</div>');
        }else{
            var tws = 'No tweets found';
            var tsh = '';
        }
        $('#load_result').text('Loading '+name+'...');
        $('.twets_con').hide();
        $('#tcon_'+name).show();
        $('#twets_'+name).empty();
        $('#twets_'+name).html(tws);
        $('#twets_'+name).append(tsh);
        SearchData();
        $('#twets_'+name)[0].scrollTop = Controller().Chrowety[name].scroll;
        $('#twets_'+name).bind("scroll", {lista:name}, Scroll);
        $('#load').hide();
        LT.ClearUnreads(name);
        window.setTimeout("Controller().ClearUnreads('"+name+"')", 1000);
        LT.UISets();
    },
    messages:function(){
        var name = 'messages';
        var loaded = Controller().Chrowety[name]._loaded;
        if(!loaded){
          Controller().Chrowety[name].scroll = 0;
          Controller().Chrowety[name].Run('LT.'+name+'()');
          return false;
        }
        db.salva('AbaAtiva', name);
        var b = $('#b'+name);
        if(b.attr('disabled')) return false;
        Button.ativa(b);
        if(Controller().fec.html(name) != ""){
            var tws = $(Controller().fec.html(name));
            var tsh = $('<div id="showMore_link_'+name+'" class="show_more" onclick="ShowMore(\''+name+'\')" title="'+Traduz('show_more')+'">'+Traduz('show_more')+'</div>');
        }else{
            var tws = 'No tweets found';
            var tsh = '';
        }
        $('#load_result').text('Loading '+name+'...');
        $('.twets_con').hide();
        $('#tcon_'+name).show();
        $('#twets_'+name).empty();
        $('#twets_'+name).html(tws);
        $('#twets_'+name).append(tsh);
        SearchData();
        $('#twets_'+name)[0].scrollTop = Controller().Chrowety[name].scroll;
        $('#twets_'+name).bind("scroll", {lista:name}, Scroll);
        $('#load').hide();
        LT.ClearUnreads(name);
        window.setTimeout("Controller().ClearUnreads('"+name+"')", 1000);
        LT.UISets();
    },
    favorites:function(){
        var name = 'favorites';
        var loaded = Controller().Chrowety[name]._loaded;
        if(!loaded){
          Controller().Chrowety[name].scroll = 0;
          Controller().Chrowety[name].Run('LT.'+name+'()');
          return false;
        }
        Controller().Chrowety[name].pagina = 1;
        db.salva('AbaAtiva', name);
        var b = $('#b'+name);
        if(b.attr('disabled')) return false;
        Button.ativa(b);
        if(Controller().fec.html(name) != ""){
            var tws = $(Controller().fec.html(name));
            var tsh = $('<div id="showMore_link_'+name+'" class="show_more" onclick="ShowMore(\''+name+'\')" title="'+Traduz('show_more')+'">'+Traduz('show_more')+'</div>');
        }else{
            var tws = 'No tweets found';
            var tsh = '';
        }
        $('#load_result').text('Loading '+name+'...');
        $('.twets_con').hide();
        $('#tcon_'+name).show();
        $('#twets_'+name).empty();
        $('#twets_'+name).html(tws);
        $('#twets_'+name).append(tsh);
        SearchData();
        $('#twets_'+name)[0].scrollTop = Controller().Chrowety[name].scroll;
        $('#twets_'+name).bind("scroll", {lista:name}, Scroll);
        $('#load').hide();
        LT.ClearUnreads(name);
        window.setTimeout("Controller().ClearUnreads('"+name+"')", 1000);
        LT.UISets();
    }
};

var Button = {
    ativa:function(el){
        Active($(el));
    }
};

function Traduz(s, e){
    return Controller().Traduz(s, e);
}

function html(r){
    return document.write(r);
}

function Alerta(){
  var html = ''
  $(document).append();
}

function LoadProfile(){
   $('#username').text(db.pega('user'));
   $('#user_nome').text(db.pega('nome'));
   $('#seguindo').html(db.pega('seguindo') + ' ' + Traduz('following'));
   $('#seguidores').html(db.pega('seguidores') + ' ' + Traduz('followers'));
   $('#foto').attr('src', db.pega('foto'));
   $('#PhotoLink').attr('href', 'http://twitter.com/home');
   $('#SeguindoLink').attr('href', 'http://twitter.com/'+db.pega('user')+'/following');
   $('#SeguidoresLink').attr('href', 'http://twitter.com/'+db.pega('user')+'/followers');
   $('.info').show();
}

String.prototype.replaceAll = function(strTarget,strSubString){
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);
    while(intIndexOfMatch != -1){
      strText = strText.replace(strTarget,strSubString)
      intIndexOfMatch = strText.indexOf(strTarget);
    }
    return(strText);
}

function RefreshResult(n, time){
    if(n > 0){
      var t = n > 1 ?
      ' '+Traduz('new_tweet').replaceAll("& ", Controller().language.plural_word+' ') :
      ' '+Traduz('new_tweet').replaceAll("& ", ' ');
      $('#new_twets_'+time).fadeIn();
      $('#new_twets_'+time).text(n+t);
	  LT.Unreads();
    }
}

function RefreshTweets(time, list){
    if(list){
        $('#new_twets_list').fadeOut();
        eval('LT.list('+time+')');
    }else{
        $('#new_twets_'+time).fadeOut();
        eval('LT.'+time+'()');
    }
    Controller().ClearUnreads();
    //LT.ClearUnreads(time);
}

function RefreshLimit(n){
    if(n){
      if(n == 0){
          $('#load_result').text(Traduz('api_excedeed'));
          $('#load_image').hide();
      }else{
          //$('#load_result').text('Remaining API: '+n);
      }
    }else{
      if(Controller().api_limit == 0){
          $('#load_result').text(Traduz('api_excedeed'));
          $('#load_image').hide();
      }else{

      }
    }

    $('#load').fadeIn();
}

function SearchData(){
  $('.tweetdata').each(function(n,w){
    $(w).html(Controller().TweetData($(w).attr('data')));
  })
}

function ShowMore(timeline, list){
    if(list){
        $('#showMore_link_list').html($('<img id="showMore_load" src="img/load.gif" />'));
        Controller().Chrowety.List.Max(timeline);
    }else{
        $('#showMore_link_'+timeline).html($('<img id="showMore_load" src="img/load.gif" />'));
        Controller().Chrowety[timeline].Max();
    }
}

function ShowMoreOK(old, timeline, list){
    $('#showMore_link_'+timeline).remove();
    if(old){
        $('#twets_'+timeline).append(old);
        SearchData();
        if(list){
            $('#twets_'+timeline).append($('<div id="showMore_link_list" class="show_more" onclick="ShowMore(\''+list+'\', true)" title="'+Traduz('show_more')+'">'+Traduz('show_more')+'</div>'));
        }else{
            $('#twets_'+timeline).append($('<div id="showMore_link_'+timeline+'" class="show_more" onclick="ShowMore(\''+timeline+'\')" title="'+Traduz('show_more')+'">'+Traduz('show_more')+'</div>'));
        }

    }else{
        $('#twets_'+timeline).append($('<div class="no_more">'+Traduz('no_more_tweets')+'</div>'));
    }
}

function Link(e, ev, h){
    if(h){
      var href = 'chrome-extension://'+location.hostname+'/conf.html';
      log('Creating Tab: '+href);
      chrome.tabs.create({url: href});
    }else{
      var b = ev.button;
      if(b==0 && Controller().config.link_in_bg !="true"){
          chrome.tabs.create({url: e.href});
      }else if(b==1 || Controller().config.link_in_bg == "true"){
          chrome.tabs.create({url: e.href, selected: false});
      }

    }
}

function DisableButton(tid, tm, str){
     //console.log('DisableButton() > '+tid+' '+tm);
     $('#twets_'+tm+' #'+(str?str:'botao_')+tid)[0].setAttribute("disabled","disabled");
}

function Count(tid, time, pulaBak){//Conta o limite de caracteres do tweet e salva backup
   var r = $('#twets_'+time+' #reply_text_'+tid);
   if(tid == 'update'){
     //log('Backup Update: '+r.val());
     db.salva('update_backup', r.val());
   }else{
     if(!pulaBak){
       //Controller().console.log('Count('+tid+', \''+time+'\')');
       BackupReply(tid, r.val(), time);
     }
   }
   var n = parseInt(140-r.val().length), el = $('#twets_'+time+' #count_'+tid);
   r.attr('count', n);
   if(n < 0){
     DisableButton(tid, time);
     el.addClass('vermelho');
   }else if(n == 140){
     DisableButton(tid, time);
   }else{
     $('#twets_'+time+' #botao_'+tid).removeAttr("disabled");
     el.removeClass('vermelho');
   }
   el.text(n);
}

function Deleta(tid, tm){
  Controller().Chrowety.deleta(tid, tm);
  $('#twets_'+tm+' #tweply_'+tid).fadeOut(function(){
    $('#twets_'+tm+' #tweply_'+tid).remove();
  });
}

function DeletaDM(tid, tm){
  Controller().Chrowety.deletaDM(tid, tm);
  $('#twets_'+tm+' #tweply_'+tid).fadeOut(function(){
    $('#twets_'+tm+' #tweply_'+tid).remove();
  });
}

function Favorite(tid, tm){
  Controller().Chrowety.favorite(tid, tm);
  $('#twets_'+tm+' #tweet_fav_'+tid).removeClass("opts");
  $('#twets_'+tm+' #tweet_fav_'+tid).addClass("dn");
  $('#twets_'+tm+' #tweet_ifav_'+tid).attr('src', 'img/favload.gif');
  $('#twets_'+tm+' #tweet_ifav_'+tid).show();
}

function UnFavorite(tid, tm){
  Controller().Chrowety.unfavorite(tid, tm);
  $('#twets_'+tm+' #tweet_fav_'+tid).addClass("dn");
  $('#twets_'+tm+' #tweet_ifav_'+tid).attr('src', 'img/favload.gif');
  $('#twets_'+tm+' #tweet_ifav_'+tid).show();
  if(tm == 'favorites'){
    $('#twets_'+tm+' #tweply_'+tid).fadeOut("slow", function(){
      $('#twets_'+tm+' #tweply_'+tid).remove();
    });
  }
}

function FavOK(tid, fav, tm){
  var Star = $('#twets_'+tm+' #tweet_fav_'+tid);
  $('#twets_'+tm+' #tweet_ifav_'+tid).hide();

  if(fav){
    $('#twets_'+tm+' #tweet_fav_'+tid).removeClass("dn");
    Star.attr({
        title: Traduz('unfavorite'),
        fav:"true",
    });
    Star.unbind();
    Star.bind("click", function(){return UnFavorite(tid, tm);});
  }else{
    Star.addClass("opts");
    Star.attr("title", Traduz('favorite'));
    Star.removeAttr('fav');
    Star.unbind();
    Star.bind("click", function(){return Favorite(tid, tm);});
  }
}

function UpdateOK(re, tm){
  $('#reply_status_update').text(Traduz('ok', '...'));
  $('#twets_'+tm).html(re+$('#twets_'+tm).html());
  UpdateCancel();
  SearchData();
  HideShortLink('update', 'update');
}

function UpdateFAIL(tid, tm, status){
  $('#reply_status_update').html('<span style="color:red">'+Traduz(status, '.')+'</span>');
}

var AtalhoDisabled = false;
function Atalho(evt, tid, tm) {
  var key = evt.keyCode;
  if(evt.ctrlKey){// Ctrl
    switch(key){
        case 8013: // Ctrl + Enter
                if(!tid && !tm){
                    //Update();
                }
                evt.returnValue=false;
                break;
        case 65: // A
                if(tid == 'update'){
                    //$('#botao_update_cancel').click();
                }else{
                    //ReplyCancel(tid, tm);
                    //$('#botao_'+tid+'_cancel').click();
                }
                //evt.returnValue=false;
                break;
    }
  }else{
    switch(key){
        case 13: // Enter
            if($('#twets_'+tm+' #botao_'+tid).attr('disabled') != "disabled" || !AtalhoDisabled){
                if(tid == 'update'){
                    if(!$("#reply_text_update").val().length){
                        evt.returnValue=false;
                    }else{
                        //DisableButton('update', 'update');
                        ///doUpdate();
                        $('#botao_update').click();
                    }
                }else{
                    if(!$('#twets_'+tm+' #reply_text_'+tid).val().length){
                        evt.returnValue=false;
                    }else{
                        if(tm == 'messages'){
                            //doReplyDM(tid, tm);
                            $('#twets_'+tm+' #botao_'+tid).click();
                            AtalhoDisabled = true;
                        }else{
                            //doReply(tid, tm);
                            $('#twets_'+tm+' #botao_'+tid).click();
                            AtalhoDisabled = true;
                        }
                    }
                }
                evt.returnValue=false;
            }
                break;
    }
  }
}

function doUpdate(){
  DisableButton('update', 'update');
  var txt = $('#reply_text_update').val();
  log('Sending update: '+txt);
  $('#reply_status_update').text(Traduz('sending', '...'));
  Controller().Chrowety.update(txt, null, 'home');
  DisableButton('update', 'update');
}

function Update(){
  if(isUp == true) return false;
  $('#reply_text_update').animate({height: "50px",opacity: 0.5}, 200,function(){
        isUp = true;
        var bak = db.pega('update_backup');
        if(bak && bak != Slogan){
           $("#reply_text_update").val(db.pega('update_backup'));
        }else{
            $("#reply_text_update").val('');
            $("#botao_share_update").removeAttr('disabled');
        }
        $("#reply_text_update").focus();
        $("#update_co2").slideDown("fast");
		var height = parseInt(Controller().config.popup_height.split('px')[0]);
		//var calc = parseInt(height-50);
		if(!$('#submenu_lists').text()){
			$('.twets').css('height', height-50+'px');	
		}else{
			$('.twets').css('height', height-70+'px');
		}
        
        LT.more(true);
        Count('update', 'update');
  });
}

function UpdateCancel(){
  $('#update_co2').slideUp("fast", function(){
  	 var height = parseInt(Controller().config.popup_height.split('px')[0]);
     $('.twets').css('height', height+50+'px');
     Count('update', 'update');
     $('#twets_update #reply_status_update').text('');
     $("#twets_update #reply_text_update").val(Slogan);
     db.deleta('update_backup');
     $('#twets_update #reply_text_update').animate({height: "20px",opacity: 0.5}, 200);
     isUp = false;
     HideShortLink('update', 'update');
  });
}

function ReplyDMFAIL(tid, time, status){//Esconde o elemento de Reply
  AtalhoDisabled = false;
  $('#twets_'+time+' #reply_status_'+tid).html('<span style="color:red">'+Traduz(status, '.')+'</span>');
  /*
  $('#twets_'+time+' #reply_'+tid).slideUp(function(){
     $('#twets_'+time+' #reply_text_'+tid).val('');
     Count(tid, time);
     HideShortLink(tid);
     $('#twets_'+time+' #reply_status_'+tid).text('');
  });
  */
}

function ReplyDMOK(tid, time){//Esconde o elemento de Reply
  AtalhoDisabled = false;
  $('#twets_'+time+' #reply_status_'+tid).text(Traduz('ok', '...'));
  $('#twets_'+time+' #reply_'+tid).slideUp(function(){
     $('#twets_'+time+' #reply_text_'+tid).val('');
     Count(tid, time);
     HideShortLink(tid);
     $('#twets_'+time+' #reply_status_'+tid).text('');
  });
}

function ReplyDM(tid, time, other){
  var bak  = $('#twets_'+time+' #reply_text_'+tid).attr('backup');
  var txt  = bak ? bak : '';
  $('#twets_'+time+' #reply_text_'+tid).removeAttr('disabled');
  $('#twets_'+time+' #retweet_choice_'+tid).hide();
  $('#twets_'+time+' #reply_rt_'+tid).show();
  $('#twets_'+time+' #botao_'+tid).removeAttr('onclick');


  $('#twets_'+time+' #botao_'+tid)[0].onclick = function(){
        doReplyDM(tid, time, (other ? true : false));
  };
  $('#twets_'+time+' #reply_'+tid).slideDown("fast", function(){
     $('#twets_'+time+' #reply_rt_'+tid).show();
     $('#twets_'+time+' #reply_text_'+tid).focus();
     $('#twets_'+time+' #reply_text_'+tid).val(txt);
     Count(tid, time, true);
     console.log($('#twets_'+time+' #botao_'+tid)[0]);
  });
}

function doReplyDM(tid, time, other){
    DisableButton(tid, time);
    var user = $('#twets_'+time+' #user_'+tid).val();
    var txt = $('#twets_'+time+' #reply_text_'+tid).val();
    Controller().console.log('Sending Message: '+txt+' to user: '+user);
    $('#twets_'+time+' #new_retweet_'+tid).hide();
    $('#twets_'+time+' #reply_status_'+tid).text(Traduz('sending', '...'));
    Controller().Chrowety.updateDM(txt, user, tid, (other ? time : null));
    BackupReplyCancel(tid, time);
}

function doReply(tid, time){
    DisableButton(tid, time);
    var txt = $('#twets_'+time+' #reply_text_'+tid).val();
    console.log('Sending: '+txt+' tid: '+tid);
    $('#twets_'+time+' #new_retweet_'+tid).hide();
    $('#twets_'+time+' #reply_status_'+tid).text(Traduz('sending', '...'));
    Controller().Chrowety.update(txt, tid, time);
    BackupReplyCancel(tid, time);
}

//> Inicio Short Link
function HideShortLink(tid, time){
    $('#twets_'+time+' #short_link_url_'+tid).animate({
            width: "1.75em",
            opacity: 0.5
    },500);
    $('#twets_'+time+' #short_link_url_'+tid).val('');
}

function ShowShortLink(tid, time){
    Controller().Utils.GetTabUrl();
    $('#twets_'+time+' #short_link_url_'+tid).animate({
            width: (tid == 'update' ? "340px" : "250px"),
            opacity: 1.0
    },500);

    chrome.tabs.getSelected(null, function(tab) {
        $('#twets_'+time+' #short_link_url_'+tid).val(tab.url);
        $('#twets_'+time+' #short_link_url_'+tid).select();
    });
}


function ShortLink(tid, time){
    var url = $('#twets_'+time+' #short_link_url_'+tid).val();
    if(!url){
        ShowShortLink(tid, time);
        return false;
    }
    $('#twets_'+time+' #short_link_url_'+tid).val(Traduz('shorting_url', '...'));
    Controller().Utils.Short.short(url, tid, time);
}

function ShortLinkOK(tid, time, url){
    $('#twets_'+time+' #short_link_url_'+tid).val(Traduz('ok', '!'));
    $('#twets_'+time+' #reply_text_'+tid).focus();
    $('#twets_'+time+' #reply_text_'+tid).val($('#twets_'+time+' #reply_text_'+tid).val()+''+url+' ');
    Count(tid, time);
    HideShortLink(tid, time);
}
//> FIM Short Link


//> Share Page
function SharePage(tid, time){
    chrome.tabs.getSelected(null, function(tab) {
        Controller().Utils.Short.short(tab.url, tid, time, 'SharePageOK');
        Controller().Utils.Short.title = tab.title;
        $('#twets_'+time+' #reply_status_'+tid).text(Traduz('wait', '...'));
    });
}
function SharePageOK(tid, time, url){
    $('#twets_'+time+' #reply_status_'+tid).text(Traduz('ok', '...'));
    var title = Controller().Utils.Short.title;
    var url   = Controller().Utils.Short.link;
    var txt   = title+': '+url;
    $('#twets_'+time+' #reply_text_'+tid).focus();
    $('#twets_'+time+' #reply_text_'+tid).val(txt);
    Count(tid, time);
    DisableButton(tid, time, 'botao_share_');
    HideShortLink(tid, time);
    $('#twets_'+time+' #reply_status_'+tid).text('');
}


function BackupReply(tid, txt, time){
    $('#twets_'+time+' #reply_text_'+tid).attr('backup', txt);
    if(time == 'list'){
        var lista = $('#tcon_list').attr('lista');
        Controller().fec.ByTid(time, tid, null, lista).reply_backup = txt;
    }else{
        Controller().fec.ByTid(time, tid).reply_backup = txt;
    }
    console.log('Backuping Reply: '+tid+' > '+txt);
}

function BackupReplyCancel(tid, time){
    $('#twets_'+time+' #reply_text_'+tid).removeAttr('backup');
    if(time == 'list'){
        var lista = $('#tcon_list').attr('lista');
        Controller().fec.ByTid(time, tid, null, lista).reply_backup = false;
    }else{
        Controller().fec.ByTid(time, tid).reply_backup = false;
    }
}

function Reply(tid, status, time){//Mostra o elemento de Reply
  //$('#twets_'+time+' ');
  var user = '@'+$('#twets_'+time+' #user_'+tid).val();
  var bak  = $('#twets_'+time+' #reply_text_'+tid).attr('backup');
  var txt  = bak && !status ? bak : (status ? status : user+' ');
  $('#twets_'+time+' #reply_'+tid).slideDown("fast", function(){
     if(status){
       $('#twets_'+time+' #reply_text_'+tid).attr('disabled', 'disabled');
       $('#twets_'+time+' #reply_rt_'+tid).hide();
       $('#twets_'+time+' #retweet_choice_'+tid).show();
     }else{
       $('#twets_'+time+' #reply_text_'+tid).removeAttr('disabled');
       $('#twets_'+time+' #retweet_choice_'+tid).hide();
       $('#twets_'+time+' #reply_rt_'+tid).show();
     }
     $('#twets_'+time+' #reply_text_'+tid).focus();
     $('#twets_'+time+' #reply_text_'+tid).val(txt);
     Count(tid, time, true);

    $('#twets_'+time+' #botao_'+tid)[0].onclick = function(){
          doReply(tid, time);
    };
  });
}

function ReplyCancel(tid, time){//Esconde o elemento de Reply
  $('#twets_'+time+' #reply_status_'+tid).text('');
  $('#twets_'+time+' #reply_'+tid).slideUp("fast", function(){
     BackupReplyCancel(tid, time);
     $('#twets_'+time+' #retweet_choice_'+tid).hide();
     $('#twets_'+time+' #reply_text_'+tid).removeAttr('disabled');
     $('#twets_'+time+' #reply_text_'+tid).val('');
     Count(tid, time);
     HideShortLink(tid);
  });
}

function ReplyOK(tid, time){//Esconde o elemento de Reply
  AtalhoDisabled = false;
  $('#twets_'+time+' #reply_status_'+tid).text(Traduz('ok', '...'));
  $('#twets_'+time+' #reply_'+tid).slideUp(function(){
     $('#twets_'+time+' #reply_text_'+tid).val('');
     init();
     Count(tid, time);
     HideShortLink(tid);
  });
}

function ReplyFAIL(tid, time, status){//Esconde o elemento de Reply
  AtalhoDisabled = false;
  $('#twets_'+time+' #reply_status_'+tid).html('<span style="color:red">'+Traduz(status, '.')+'</span>');
}

function RetweetOficial(tid, time){//Mostra o elemento do Reply com o Retweet
  DisableButton(tid, time, 'rt_now_');
  log('Retweeting... tid: '+tid);
  $('#twets_'+time+' #edit_rt_'+tid).hide();
  $('#twets_'+time+' #rt_now_'+tid).text(Traduz('wait', '...'));
  $('#twets_'+time+' #reply_status_'+tid).text(Traduz('retweeting', '...'));
  Controller().Chrowety.retweet(tid, time);
}

function RetweetEdit(tid, time){
    $('#twets_'+time+' #reply_text_'+tid).removeAttr('disabled');
    $('#twets_'+time+' #reply_status_'+tid).text('');
    $('#twets_'+time+' #retweet_choice_'+tid).hide();
    $('#twets_'+time+' #reply_rt_'+tid).show();
    var a = $('#twets_'+time+' #reply_text_'+tid).val();
    $('#twets_'+time+' #reply_text_'+tid).val('');
    $('#twets_'+time+' #reply_text_'+tid).focus();
    $('#twets_'+time+' #reply_text_'+tid).val(a);
}

function Retweet(tid, time){//Mostra o elemento do Reply com o Retweet
  var user = '@'+$('#twets_'+time+' #user_'+tid).val(),
      txt = 'RT '+user+': '+$('#twets_'+time+' #texto_'+tid).text();
  Reply(tid, txt, time);
}

function RetweetRT(tid, time){//Mostra o elemento do Reply com o Retweet
  var txt = unescape($('#twets_'+time+' #texto_'+tid).attr("data"));
  Reply(tid, txt, time);
}

function RetweetOK(tid, time){
  AtalhoDisabled = false;
  $('#twets_'+time+' #reply_status_'+tid).text(Traduz('ok', '...'));
  $('#twets_'+time+' #reply_'+tid).slideUp(function(){
     $('#twets_'+time+' #reply_text_'+tid).val('');
     $('#twets_'+time+' #edit_rt_'+tid).show();
     $('#twets_'+time+' #rt_now_'+tid).removeAttr('disabled');
     $('#twets_'+time+' #rt_now_'+tid).text(Traduz('retweet_now'));
  });
}

function RetweetFAIL(tid, time, status){
  AtalhoDisabled = false;
  $('#twets_'+time+' #reply_status_'+tid).html('<span style="color:red">'+Traduz(status, '.')+'</span>');
  $('#twets_'+time+' #edit_rt_'+tid).show();
  $('#twets_'+time+' #rt_now_'+tid).removeAttr('disabled');
  $('#twets_'+time+' #rt_now_'+tid).text(Traduz('retweet_now'));
}

function LoginStatus(t){
    var re = $('#status_login');
    re.text(t);
}

function GoLogin(){
  $('#init').fadeOut(function(){
     $('#OAuthLogin').fadeIn();
     window.close();
  });
}

function PictureZoom(el, outforce){
    var zoom = $(el).attr('zoom');
    if(zoom == 'in' && !outforce){
        var newsrc = $(el).attr('src').replace('_bigger', '');
        var newImage = new Image();
        newImage.src = newsrc;
        $('#user_data').hide();
        $('#user_rest').hide();
        $(el).animate({height: "300px", width: "300px"}, 600,function(){
            $(el).attr('zoom', 'out');
            $(el).attr('src', newsrc);
        });
    }else{
        $('#user_data').show();
        $('#user_rest').show();
        $(el).animate({height: "100px", width: "100px"}, 600,function(){
            $(el).attr('zoom', 'in');
        });
    }

}

function ShowUser(uname){
    $('.popup_bg').fadeIn();
    Controller().Chrowety.profile_last_view = uname;
    Controller().Chrowety.user(uname);
}

function ShowUserERRO(func){
    Controller().Utils.Twitpic.vendo = null;
    Controller().Chrowety.profile_last_view = null;
    $('#user_protegido').addClass('dn');
    $('#user_info').hide();
    $('#user_unome').empty();
    $('#user_uname').empty();
    $('#user_uname').attr('href', '');
    $('#user_local').empty();
    $('#user_bio').empty();
    $('#user_link').attr('href', '');
    $('#user_link').empty();
    $('#user_photo').attr('src', '');
    $('#user_followers').empty();
    $('#user_following').empty();
    $('#user_tweets').empty();
    $('#user_update').empty();
    $('#user_update_data').empty();
    $('#user_update_data').attr('href', '');
    $('#user_update_via').empty();
    $('#following_re').empty();
    PictureZoom($('#user_photo'), true);
    $('.popup').css('min-height', '200px');
    HidePopup();
    if(func){func();}
}

function HidePopup(){
    $('.popup').hide();
    $('#youtube_preview').hide();
    $('#twitpic_preview').hide();
    $('#user_info').hide();
    $('#quick_profile').hide();
    $('#add_photo').hide();
    $('#show_lists').hide();
    $('.popup_bg').hide();
}

function ShowPopup(){
    $('.popup_bg').show();
    $('.popup').fadeIn("fast");
    var lef = ( ($('#init').css('width').split('px')[0]) - ($('.popup').css('width').split('px')[0]) ) / 2;
    var top = ( ($('#init').css('height').split('px')[0]) - ($('.popup').css('height').split('px')[0])) / 2;
    //Controller().console.log('popup left: '+lef);
    $('.popup').css({
     'margin-left':lef+'px',
     'margin-top':top+'px',
    });
}

function ShowUserOK(user){
    var u = user;

    $('#user_unome').text(u.name);
    $('#user_uname').text('@'+u.screen_name);
    $('#user_uname').attr('href', 'http://twitter.com/'+u.screen_name);
    $('#user_local').text(u.location);
    $('#user_local_link').attr('title', u.location);
    $('#user_local_link').attr('href', 'http://maps.google.com/?z=17&q='+u.location);
    $('#user_bio').text(u.description);
    $('#user_link').attr('href', u.url);
    $('#user_link').text(u.url);
    $('#user_photo').attr('src', u.profile_image_url.replace('_normal', '_bigger'));
    $('#user_followers').text(u.followers_count);
    $('#user_following').text(u.friends_count);
    $('#user_tweets').text(u.statuses_count);
    $('#user_since').text(Controller().SinceDate(u.created_at));

    if(u.verified){
        $('#user_verified').show();
    }else{
        $('#user_verified').hide();
    }
    if(!u.following){
        $('#following_re').empty();
        $('#following_re').html(Traduz('no'));
    }else{
        $('#following_re').empty();
        $('#following_re').html(Traduz('yes'));
    }

    if(!u.protected){
        var data = Controller().TweetData(u.status.created_at);
        var source = u.status.source.replace('rel=\"nofollow\"', 'class="cinza p8 source" onclick="Link(this, event);"');
        var txt = u.status.text;
        txt = txt.replace(/(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?^twitpic^tweetphoto^pic.gd^youtube.com\/watch\?v=)(\s|&gt;|$)/g,' <a class="url" title="$2" href="$2" onclick="Link(this, event);">$2</a> ');
        txt = txt.replace(/((https?):\/\/twitpic.com\/([a-zA-Z_0-9]*|$))/g,' <a class="url" nohref="$1" title="$1" onclick="Twitpic(\'$3\');">$1</a>');
        txt = txt.replace(/((https?):\/\/(tweetphoto.com|www.tweetphoto.com\/|pic.gd\/)([a-zA-Z_0-9]*|$))/g,' <a class="url" nohref="$1" title="$1" onclick="Tweetphoto(\'$1\');">$1</a>');
        txt = txt.replace(/((https?):\/\/(www.youtube.com\/watch\?v=|youtube.com\/watch\?v=)([a-zA-Z_0-9]*|$))/g,' <a class="url" nohref="$1" title="$1" onclick="Youtube(\'$4\');">$1</a>');
        txt = txt.replace(/(^|&lt;|\s)((www).+?)(\s|&gt;|$)/g,' <a class="url" title="$2" href="http://$2" onclick="Link(this, event);">$2</a> ');
        txt = txt.replace(/(@|$)([a-zA-Z_0-9]*|$)/g,' $1<a class="usuario" title="$2" nohref="http://twitter.com/$2" onclick="ShowUser(\'$2\')">$2</a>');
        txt = txt.replace(/(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g,' <a class="url" title="$2" href="$2" onclick="Link(this, event);">$2</a> ');
        txt = txt.replace(/(^|&lt;|a-zA-Z_0-9|\s)(#|$)([_a-zA-Z_0-9]*|$)/g,' $2<a class="tag" title="$3" href="http://twitter.com/search?q=%23$3" onclick="Link(this, event);">$3</a>');
        $('#user_update').html(txt);
        $('#user_update_data').text(data);
        $('#user_update_data').attr('href', 'http://twitter.com/'+u.screen_name+'/status/'+u.status.id+'');
        $('#user_update_via').html(' via '+source);
        $('#user_update_div').show();
    }else{
        $('#user_protegido').removeClass('dn');
        $('#user_update_div').hide();
    }
    $('#user_info').show();
    ShowPopup();
}

function Twitpic(id){
    var url = Controller().Utils.Twitpic.thumb(id);
    $('#twitpic_link').attr('href', 'http://twitpic.com/'+id);
    $('#twitpic_photo').attr('src', url);
    $('#twitpic_preview').show();
    $('#user_info').hide();
    ShowPopup();
}

function Tweetphoto(id){
    var url = Controller().Utils.Tweetphoto.thumb(id);
    $('#twitpic_link').attr('href', id);
    $('#twitpic_photo').attr('src', url);
    $('#twitpic_preview').show();
    $('#user_info').hide();
    $('.popup').css('min-height', '200px');
    ShowPopup();
}

function AddPhoto(tid, tm){
    $('#user_info').hide();
    //$('#quick_profile').css('vertical-align', 'middle');
    //$('.popup').css('min-height', '10px');
    ShowPopup();
    $('#add_photo').show();
    //$('#quick_profile_name').focus();
    //$('#quick_profile_name').select();
}


function QuickProfile(){
    $('#user_info').hide();
    $('#quick_profile').css('vertical-align', 'middle');
    $('.popup').css('min-height', '10px');
    ShowPopup();
    $('#quick_profile').show();
    $('#quick_profile_name').focus();
    $('#quick_profile_name').select();
}

function doQuickProfile(){
    if($('#quick_profile_name').val()){
        ShowUserERRO(function(){
            ShowUser($('#quick_profile_name').val());
        });
    }else{
        $('#quick_profile_name').focus();
    }
    return false;
}

function Youtube(id){
    var url = "http://www.youtube.com/v/"+id;
    var url2 = "http://www.youtube.com/watch?v="+id;
    $('#youtube_link').attr('href', url2);
    $('#youtube_param').attr('movie', url);
    $('#youtube_embed').attr('src', url);
    $('#youtube_preview').show();
    $('#user_info').hide();
    ShowPopup();
}

function Traduzir(tid, tm){
    Controller().console.log('Traduzir()');
    var el = $('#twets_'+tm+' #texto_'+tid);
    var txt = unescape(el.attr('data'));
    var html = unescape(el.attr('html'));
    if(el.attr('traduzido')){
      el.html(html);
      el.removeAttr('traduzido');
    }else{
      Controller().Utils.Translate.trans(txt, tid, tm);
    }
}

function TraduzirOK(txt, tid, tm){
    Controller().console.log('TraduzirOK()');
    var el = $('#twets_'+tm+' #texto_'+tid);
    el.attr('traduzido', true);
    el.html(txt);
}

function TraduzirFAIL(re, tid, tm){
    Controller().console.log('TraduzirFAIL()');
    Controller().console.log(re);
}

function OAuthLogin(){
    Controller().OAuth.Autorisar();
    return false;
}

function Login(){
  var user  = $('#usuario').val();
  var senha = $('#senha').val();
  var lembra = $('#lembrar').val();

  var re = $('#status_login');

  if(!user || !senha){
      re.fadeIn();
      if(!senha){
          re.text(Traduz('password_empty'));
      }
      if(!user){
          re.text(Traduz('user_empty'));
      }
  }else{
      re.fadeIn();
      Controller().Login(user, senha, lembra);
      re.text(Traduz('logging'));
  }

  return false;
}

function RequestToken(){
    $('#autorize_button')[0].setAttribute("disabled","disabled");
    $('#autorize_button').html('<img id="autorize_image" src="img/load.gif" />');
    Controller().OAuth.DeletaToken('Popup().init()');
}

function init(){
  if(!Controller().Logado){
    $('#OAuthLogin').show();
    if(Controller().OAuth.token.oauth_token){
      $('#autorize_button').text(Traduz('sign_in_with_twitter'));
      $('#autorize_button').removeAttr('disabled');
    }else{
      Controller().OAuth.RequestToken();
    }
    LoginUp = true;
    return false;
  }

  document.charset = Controller().language.charset;
  $('meta')[0].charset = Controller().language.charset;

  LoginUp = false;

  LoadProfile();
  RefreshLimit();
  $('#bempty').hide();
  $('#OAuthLogin').hide();
  $('#reply_text_update').val(Slogan);
  $('#init').show();

  if(Controller().Chrowety.profile_last_view){
    window.setTimeout('ShowUser(Controller().Chrowety.profile_last_view)', 90);
  }
  if(Controller().Utils.Twitpic.vendo){
    window.setTimeout('Twitpic(Controller().Utils.Twitpic.vendo)', 90);
  }
  LT.initLists();
  LT.Auto();
}

$(document).ready(init);
</script>
</head>
<body>
<div id="init" class="init dn" onkeydown="Atalho(event)">
  <div class="menu">
    <div id="load" class="load fr">
        <span id="load_result" class="fl"><script>html(Traduz('loading', '...'))</script></span>
        <img id="load_image"src="img/load.gif" class="fl"/>
    </div>

    <div class="info dn">
      <a id="PhotoLink" onclick="Link(this, event);"><img id="foto" width="32" height="32" src="" class="photo fl"/></a>
      <span class="fl">
        <span id="user_nome" class="p8"></span> <span class="cinza">(<span id="username" class="p8"></span>)</span> -
        <a class="p8" href="javascript:Controller().Logout();GoLogin();">
          <script>html(Traduz('logout'))</script>
        </a>
        <br />
        <a id="SeguindoLink" class="cinza p8" onclick="Link(this, event);"><span id="seguindo"></span></a> | <a id="SeguidoresLink" class="cinza p8" onclick="Link(this, event);"><span id="seguidores"></span></a>
      </span>
    </div>
    <button class="alerta" alerta="true" id="bhome" onclick="LT.home();"><script>html(Traduz('home'))</script></button>
    <button id="bmentions" onclick="LT.mentions();"><script>html(Traduz('mentions'))</script></button>
    <button id="bmessages" onclick="LT.messages();"><script>html(Traduz('messages'))</script></button>
    <button id="bfavorites" onclick="LT.favorites();"><script>html(Traduz('favorites'))</script></button>
    <button id="blists" onclick="LT.Lists()"><script>html(Traduz('lists'))</script></button>
 <!--
    <button id="bmore" onclick="LT.more('more');">More</button>
    <button id="bpainel" class="PainelButton fr" onclick="SwichPainel();" disabled="disabled"><img id="PainelSeta" class="dn"/></button>
-->
    <img title="Configuration" class="pointer fr" onclick="Link(this, event, true);" src="img/conf.png"/>
  </div>
  
  <div id="submenu_lists" class="submenu centro "></div>
  	
  <div id="submenu_more" class="submenu centro dn">
    <button id="botao_profile" onclick="QuickProfile();">Quick profile</button>
    <button id="botao_profile" onclick="AddPhoto();">Add Phtoo</button>
  </div>

  <div class="timeline"><!-- TIMELINE> -->
  <div id="twets_update" class="update">
    <input type="hidden" id="update_type" value="update"/>
    <input type="hidden" id="dm_user" value=""/>
    <textarea id="reply_text_update" onclick="Update();" onkeydown="Atalho(event, 'update', 'home')" onkeyup="Count('update', 'update')" class="t1"></textarea>
    <div id="update_co2" class="text2 dn">
      <div class="short fl" title="Short a Link">
        <button onclick="ShortLink('update', 'update')"  class="button fl">
            <img src="img/link.png" height="16" />
        </button>
        <input onfocus="ShowShortLink('update', 'update')" class="short_link_url fl" id="short_link_url_update" type="text" />
      </div>
      <br/><br/>
      <button class="button_margin" id="botao_update" onclick="doUpdate()" title="Done (Enter)"><script>html(Traduz('done'))</script></button>
      <button class="button_margin" id="botao_share_update" onclick="SharePage('update', 'update')" title=""><script>html(Traduz('share_page'))</script></button>
      <a id="botao_update_cancel" onclick="UpdateCancel()" title="Cancel" class="p8"><script>html(Traduz('cancel'))</script></a>
      <span id="count_update" class="p13">140</span>
      <span id="reply_status_update" class="state"></span>
    </div>
  </div>

  <div id="tconMaster">
      <div id="tcon_home" class="twets_con dn">
        <div id="new_twets_home" class="new_twets dn" onclick="RefreshTweets('home')"></div>
        <div id="twets_home" class="twets">
            <div class="tload"><img src="img/load.gif" /></div>
        </div>
      </div>

      <div id="tcon_mentions" class="twets_con dn">
        <div id="new_twets_mentions" class="new_twets dn" onclick="RefreshTweets('mentions')"></div>
        <div id="twets_mentions" class="twets">
            <div class="tload"><img src="img/load.gif" /></div>
        </div>
      </div>

      <div id="tcon_messages" class="twets_con dn">
        <div id="new_twets_messages" class="new_twets dn" onclick="RefreshTweets('messages')"></div>
        <div id="twets_messages" class="twets">
            <div class="tload"><img src="img/load.gif" /></div>
        </div>
      </div>

      <div id="tcon_favorites" class="twets_con dn">
        <div id="new_twets_favorites" class="new_twets dn" onclick="RefreshTweets('favorites')"></div>
        <div id="twets_favorites" class="twets">
            <div class="tload"><img src="img/load.gif" /></div>
        </div>
      </div>

      <div id="tcon_list" class="twets_con dn">
        <div id="new_twets_list" class="new_twets dn" onclick="RefreshTweets(this.parentNode.getAttribute('lista'), true)"></div>
        <div id="twets_list" class="twets">
            <div class="tload"><img src="img/load.gif" /></div>
        </div>
      </div>

  </div>

  <div class="popup_bg dn" onclick="ShowUserERRO();"></div>

  <div class="popup dn">
    <span class="popup_close fr" onclick="ShowUserERRO();">X</span>

    <div id="quick_profile" class="dn centro">
        <div class="short fl" title="Quick Profile" style="padding-top:5px">
          <form onsubmit="return doQuickProfile();">
            <button onclick="doQuickProfile();" class="button fl" style="line-height:1.2em"><script>html(Traduz('username'))</script></button>
            <input class="fl" id="quick_profile_name" type="text" />
          </form>
        </div>
    </div>

    <div id="youtube_preview" class="dn centro">
        <a id="youtube_link" class="cinza" onclick="Link(this, event);">
            <span class="p12 oceania fl"><script>html(Traduz('watch_on_youtube'))</script></span>
        </a>
        <br /><br />
        <object width="300" height="219" class="cb">
          <param id="youtube_param" name="movie" value="" />
          <param name="allowFullScreen" value="true" />
          <param name="allowscriptaccess" value="always" />
          <embed id="youtube_embed" src="" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="219" />
        </object>
    </div>

    <div id="show_lists" loaded="false" class="dn centro" style="padding-top:5px;width:250px;">
        <span class="p12 oceania fl"><script>html(Traduz('add_list', true))</script></span>
        <div class="short" style="padding-top:5px;width:250px;">
          <div class="opts">
            <a onclick="LT.Lists(true);"><script>html(Traduz('reload_lists'))</script></a>
          </div>
          <div id="show_lists_load">
                <img id="show_lists_load_image" class="fl" src="img/load.gif" />
                <span class="fl" style="margin-left:5px;">
                    <script>html(Traduz('loading'))</script>
                </span>
                <br />
          </div>
          <div id="show_lists_lists" class="dn"></div>
<!--
          <br />
          <div class="opts">
            <button onclick="doQuickProfile();" class="button fl" style="line-height:1.2em"><script>html(Traduz('username'))</script></button>
            <input class="fl" id="quick_profile_name" type="text" />
          </div>
          <br /><br />
-->
        </div>
    </div>

    <div id="add_photo" class="dn centro">
        <div class="short fl" title="Quick Profile" style="padding-top:5px">
          <span class="p12 oceania fl">Add Photo</span>
          <br /><br />
          <form onsubmit="return doQuickProfile();">
            <button onclick="" class="button fl" style="line-height:1.2em">Select Photo</button>
            <input class="fl" id="quick_profile_name" type="text" />
            <br /><br />
            <button class="button fl" style="line-height:1.2em"><script>html(Traduz('username'))</script></button>
            <input class="fl" id="quick_profile_name" type="text" />
            <br /><br />
            <button class="button fl" style="line-height:1.2em"><script>html(Traduz('password'))</script></button>
            <input class="fl" id="quick_profile_name" type="text" />
            <br /><br /><br />
            <button onclick="doQuickProfile();" class="button fl" style="line-height:1.2em"><script>html(Traduz('done'))</script></button>
            <br />
            <button onclick="window.open('Upload.html','name','height=400,width=400');" class="button fl" style="line-height:1.2em">Popup</button>
          </form>
        </div>
    </div>

    <div id="twitpic_preview" class="dn centro">
        <br /><br />
        <a id="twitpic_link" onclick="Link(this, event);">
            <img id="twitpic_photo" class="photo" width="250"/>
        </a>
    </div>

    <div id="user_info" class="dn">
        <div style="height:100px">
          <img id="user_photo" title="Click to Zoom" onclick="PictureZoom(this);" width="100" height="100" class="photo fl" zoom="in" src=""/>
          <span id="user_data" class="fl">
               <span id="user_protegido" class="cadeado dn" title="Protected">Protegido</span>
               <span id="user_unome" class="p12 oceania"></span><br />
               <span><a id="user_uname" onclick="Link(this, event);"></a></span><br />
               <a class="cinza" onclick="Link(this, event);" id="user_local_link"><span id="user_local"></span></a><br />
               <span><script>html(Traduz('member_since'))</script>: <span id="user_since"></span></span><br />
               <span id="user_follow" class="dn">
                 <script>html(Traduz('following_you',':'))</script>
                 <span id="following_re"></span>
               </span><br />
               <img id="user_verified" src="img/verified.png" class="dn"/>
          </span>
        </div>
        <div id="user_rest">
	        <br />
	        <div id="user_bio_div" class="cb">
	            <span><a id="user_link" href="" onclick="Link(this, event)"></a></span><br />
	            <span id="user_bio"></span>
	            <br /><br />
	        </div>
	        <div class="centro" style="border-top:1px solid #ddd;border-bottom:1px solid #ddd;">
	            <span class="centro inblock" style="width:70px">
	              <span id="user_followers"></span>
	              <br />
	              <span><script>html(Traduz('followers'))</script></span>
	            </span>
	
	            <span class="centro inblock" style="width:70px">
	              <span id="user_following"></span>
	              <br />
	              <span><script>html(Traduz('following'))</script></span>
	            </span>
	
	            <span class="centro inblock" style="width:70px">
	              <span id="user_tweets"></span>
	              <br />
	              <span><script>html(Traduz('tweets'))</script></span>
	            </span>

	            <span class="centro inblock dn" style="width:70px">
	              <span id="user_lists"></span>
	              <br />
	              <span><script>html(Traduz('lists'))</script></span>
	            </span>				
	        </div>
	        <div id="user_update_div" class="dn">
	            <br /><br />
	            <b><script>html(Traduz('last_update'))</script>: </b>
	            <span id="user_update"></span><br />
	            <span class="p8 cinza"><a class="p8 cinza" id="user_update_data" onclick="Link(this, event);"></a><span id="user_update_via"></span></span>
	        </div>
			<br>
			<div id="user_options_div" class="user_profile_options dn">
				<span class="user_opt r_bl r_tl">Follow</span>
				<span class="user_opt">Unfollow</span>
				<span class="user_opt">Add To List</span>	
			</div>
        </div>
    </div>
  </div>

  </div><!-- <TIMELINE -->
</div>

<div id="OAuthLogin" class="login dn">
    <form onsubmit="return OAuthLogin();">
      <br />
      <button disabled="disabled" id="autorize_button" type="submit"><img id="autorize_image" src="img/load.gif" /></button>
      <br /><br />
      <a onclick="RequestToken();" class="p8">(<script>html(Traduz('request_new_auth'))</script>)</a>
      <br />
      <br />
    </form>
    <script>html(Traduz('or'))</script>
    <br /><br />
    <div class="bar pointer" onclick="$('#api_login').slideToggle(function(){$('#usuario').focus();});">API Login</div>
    <form id="api_login"class="dn" onsubmit="return Login();">
      <br />
      <label class="inp"><script>html(Traduz('username'))</script>:
          <input id="usuario" type="text" size="10" tabindex="1"/>
      </label>
      <br /><br />
      <label class="inp"><script>html(Traduz('password'))</script>:
          <input id="senha" type="password" size="10" tabindex="2" />
      </label>
      <br /><br />
      <label class="check">
          <input id="lembrar" type="checkbox" tabindex="3"/>
          <script>html(Traduz('remember'))</script>
      </label>
      <br /><br />
      <button type="submit" tabindex="3"><script>html(Traduz('login'))</script></button>
      <br /><br />
      <span id="status_login" class="dn"></span>
    </form>
</div>

</body>
</html>